package com.jinzhi.jzweb.controller;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.utils.ApiResult;
import com.jinzhi.common.utils.Result;
import com.jinzhi.jzapi.domain.UserDO;
import com.jinzhi.jzapi.utils.JWTUtil;
import com.jinzhi.jzweb.domain.JazGroupProdDO;
import com.jinzhi.jzweb.domain.JazShippingAddressDO;
import com.jinzhi.jzweb.service.JazShippingAddressService;

import com.jinzhi.sys.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 *
 * <pre>
 * 用户收货地址表
 * </pre>
 * <small> 2023-02-16 09:04:41 | lance</small>
 */
@Slf4j
@RestController
@RequestMapping("/integralUserShippingAddress")
public class JazShippingAddressController {


	private final JazShippingAddressService jazShippingAddressService;

	public JazShippingAddressController(JazShippingAddressService jazShippingAddressService){
		this.jazShippingAddressService = jazShippingAddressService;
	}




	/**
	 * 新增收货地址
	 *
	 * @param receivingName 姓名
	 * @param phone         联系电话
	 * @param province      省
	 * @param city          市
	 * @param district      区
	 * @param address       详细地址
	 * @return
	 */
	@PostMapping("/saveIntegralUserShippingAddress")
	public Result<?> saveIntegralUserShippingAddress(String receivingName, String phone, String province, String city,
													 String district, String address) {

		return jazShippingAddressService.saveIntegralUserShippingAddress(receivingName,phone,province,city,district,address);
	}


	/**
	 * 查询指定用户的收货地址
	 *
	 * @return
	 */
	@GetMapping("/selectByAddress")
	public Result<?> selectByAddress(String current, String size) {

		return jazShippingAddressService.selectByAddress(current,size);
	}


	/**
	 * 查询指定用户的默认收货地址
	 *
	 * @param userId
	 * @return
	 */
	@GetMapping("/selectByIsDefaultAddress")
	public Result<?> selectByIsDefaultAddress(String userId) {

		return jazShippingAddressService.selectByIsDefaultAddress(userId);
	}


	/**
	 * 收货地址详情查询
	 *
	 * @return
	 */
	@GetMapping("/addressParticulars")
	public Result<?> addressParticulars(String addressId) {
		return Result.ok(jazShippingAddressService.selectById(addressId));
	}


	/**
	 * 设置默认地址
	 *
	 * @return
	 */
	@PostMapping("/setIsDefault")
	@Transactional
	public Result<?> setIsDefault(String addressId, String userId) {

		return jazShippingAddressService.setIsDefault(addressId,userId);
	}


	/**
	 * 删除指定地址
	 */
	@PostMapping("/delAddress")
	@Transactional
	public Result<?> delAddress(String addressId) {

		return jazShippingAddressService.delAddress(addressId);
	}


	/**
	 * 修改收货地址
	 *
	 * @param addressId     地址id
	 * @param receivingName 姓名
	 * @param phone         联系电话
	 * @param province      省
	 * @param city          市
	 * @param district      区
	 * @param address       详细地址
	 */
	@PostMapping("/updateAddress")
	@Transactional
	public Result<?> updateAddress(String addressId, String receivingName, String phone, String province, String city,
									  String district, String address) {

		return jazShippingAddressService.updateAddress(addressId,receivingName,phone,province,city,district,address);
	}
}
